package cn.edu.scau.cmi.zengGuanSheng.spring.client;

import javafx.fxml.FXML;

import javafx.scene.control.TextField;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;

import cn.edu.scau.cmi.zengGuanSheng.spring.domain.Student;
import cn.edu.scau.cmi.zengGuanSheng.spring.util.ApplicationContextUtil;
import javafx.event.ActionEvent;

import javafx.scene.control.TextArea;

public class SpringClientController {
	@FXML
	private TextField textField;
	@FXML
	private TextArea textArea_show;

	// Event Listener on TextField[#textField].onAction
	@FXML
	public void eventEnter(ActionEvent event) {
		// TODO Autogenerated
		textArea_show.setText(null);
		String s = textField.getText().trim();
		if (s.equals("")) {
			textArea_show.setText("请先输入学生的姓名拼音");
		} else {
			ApplicationContext applicationContext = ApplicationContextUtil.getApplicationContext();
			try {
				Student student = (Student) applicationContext.getBean(s);
//				textArea_show.appendText("ID:" + student.getId() + "\r\n");
				textArea_show.appendText("姓名:" + student.getName() + "\r\n");
				textArea_show.appendText("性别:" + student.getGendar() + "\r\n");
				textArea_show.appendText("指导教师:" + student.getTutor().getName());
			}catch(NoSuchBeanDefinitionException e) {
				textArea_show.setText("该学生不存在");
			}

		}
	}
}
